#include <iostream>

using namespace std;

// 组件接口
class Component
{
public:
    virtual ~Component(){};
    virtual std::string operation() const = 0;

};
// 具体对象（外部行为扩展的对象）
//后面在扩展功能 就是在这个对象的基础上扩展
class ConcreteComponent:public Component
{
public:
    std::string operation() const override
    {
        return "base Component";
    }
};


// 装饰其
class Decorator:public Component
{
public:
    Decorator(  Component * _compent)
    {
        compent = _compent;
    }
    std::string operation() const override
    {
        return this->compent->operation();
    }
protected:
    Component * compent;

};


//装饰其的 具体行为（扩展的功能A）
class  DecoratorA: public Decorator
{
public:
    DecoratorA(Component * _compent):Decorator(_compent)
    {

    }
    std::string operation() const override
    {
        return "DecoratorA  + "  + Decorator::operation();
    }

};
//装饰其的 具体行为（扩展的功能B）
class  DecoratorB: public Decorator
{
public:
    DecoratorB(Component * _compent):Decorator(_compent)
    {

    }
    std::string operation() const override
    {
        return "DecoratorB  + "  + Decorator::operation();
    }

};
int main()
{
    cout << "Hello World!" << endl;
    Component* compent = new ConcreteComponent;
    Component *DectorA = new DecoratorA(compent);
    Component *DectorB = new DecoratorB(DectorA);
    std::cout<<DectorB->operation()<<std::endl;


    return 0;
}

